package com.ruoyi.web.controller.system.api.cc;

import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.framework.interceptor.Authentication;
import com.ruoyi.system.api.ResponseWithData;
import com.ruoyi.system.api.domain.*;
import com.ruoyi.system.api.mapper.StInfoUpdateMapper;
import com.ruoyi.system.api.service.CcService;
import com.ruoyi.system.api.service.IServiceNoticeService;
import com.ruoyi.system.api.service.IStInfoUpdateService;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.api.service.IServiceInstrumentService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 服务派单涉及到的仪器信息 (数据来源于CC端主动调用，和服务派单主信息一起入库)Controller
 *
 * @author shihx
 * @date 2020-03-05
 */
@Api(tags = "服务派单涉及到的仪器信息 (数据来源于CC端主动调用，和服务派单主信息一起入库)")
@Controller
@RequestMapping("/api/cc/instrument")
public class ServiceInstrumentController extends BaseController {


    @Autowired
    private IServiceInstrumentService serviceInstrumentService;

    @Autowired
    private CcService ccService;

    @Autowired
    private IServiceNoticeService serviceNoticeService;
    @Autowired
    private StInfoUpdateMapper stInfoUpdateMapper;
    private static final Logger log = LoggerFactory.getLogger(ServiceInstrumentController.class);


    /**
     * 获取该服务单下仪器信息接口
     *
     * @param ServiceNoticeId
     * @methodName: getServiceInstrument
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020/3/5 9:36
     **/
    @GetMapping("/getServiceInstrument")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "获取该服务单下仪器信息接口", httpMethod = "GET", notes = "获取该服务单下仪器信息接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务单主键ID", name = "ServiceNoticeId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功", response = FseLocation.class)
    })
    public ResponseWithData<?> getServiceInstrument(@RequestParam(value = "ServiceNoticeId", required = true) String ServiceNoticeId) {
        try {
            ServiceInstrument serviceInstrument = new ServiceInstrument();
            serviceInstrument.setServiceNoticeId(Long.parseLong(ServiceNoticeId));
            List<ServiceInstrument> serviceInstruments = serviceInstrumentService.selectServiceInstrumentList(serviceInstrument);
            return new ResponseWithData<>().success(serviceInstruments).msg("查询成功").code(200);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 2.5TL设置仪器指定FSE接口
     *
     * @param ServiceNoticeId
     * @param ServiceNo
     * @param TeamleaderId
     * @param AccoutfseId
     * @param AccoutfseName
     * @methodName: setPartAccountFSE
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020/3/6 16:42
     **/
    @Log(title = "2.5TL设置仪器指定FSE接口", businessType = BusinessType.UPDATE)
    @GetMapping("/setPartAccountFSE")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "2.5TL设置仪器指定FSE接口", httpMethod = "GET", notes = "2.5TL设置仪器指定FSE接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务单主键ID", name = "ServiceNoticeId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务单号", name = "ServiceNo", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "TL主键ID", name = "TeamleaderId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "仪器指定FSE的ID", name = "AccoutfseId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "仪器指定FSE的姓名", name = "AccoutfseName", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功", response = InstrumentInfo.class)
    })
    public ResponseWithData<?> setPartAccountFSE(
            @RequestParam(value = "ServiceNoticeId", required = true) String ServiceNoticeId,
            @RequestParam(value = "ServiceNo", required = true) String ServiceNo,
            @RequestParam(value = "TeamleaderId", required = true) String TeamleaderId,
            @RequestParam(value = "AccoutfseId", required = true) String AccoutfseId,
            @RequestParam(value = "AccoutfseName", required = true) String AccoutfseName
    ) {
        try {
            return serviceInstrumentService.setPartAccountFSE(ServiceNoticeId, ServiceNo, TeamleaderId, AccoutfseId, AccoutfseName);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 核对序列号接口
     *
     * @param ServiceNoticeId
     * @param serialNumber
     * @methodName: checkSerialNumber
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020/3/9 16:35
     **/
    @GetMapping("/checkSerialNumber")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "核对序列号接口", httpMethod = "GET", notes = "核对序列号接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务单主键ID", name = "ServiceNoticeId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "仪器序列号", name = "serialNumber", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> checkSerialNumber(
            @RequestParam(value = "ServiceNoticeId", required = true) String ServiceNoticeId,
            @RequestParam(value = "serialNumber", required = true) String serialNumber
    ) {
        try {
            return serviceInstrumentService.checkSerialNumber(ServiceNoticeId, serialNumber);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }


    /**
     * 检查服务通知是否核对序列号
     *
     * @methodName: checkSerialNumber
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020/3/9 16:35
     **/
    @GetMapping("/checkSerialNumberByServiceNotice")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "核对序列号接口", httpMethod = "GET", notes = "核对序列号接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务单主键ID", name = "serviceNo", required = true, defaultValue = "10009", dataType = "String", paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> checkSerialNumberByServiceNotice(
            @RequestParam(value = "serviceNo", required = true) String serviceNo
    ) {
        try {
            ServiceNotice serviceNoticeTemp = new ServiceNotice();
            serviceNoticeTemp.setServiceNo(serviceNo);
            List<ServiceNotice> serviceNotices = serviceNoticeService.getTeamServiceNotice(serviceNoticeTemp);
            ServiceNotice serviceNoticeCheck = serviceNotices.get(0);
            if ("2".equals(serviceNoticeCheck.getIsCheck())) {
                return new ResponseWithData().success().msg("已核对").code(207);
            } else {
                return new ResponseWithData().success().msg("未核对").code(206);
            }

        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 检查服务通知是否核对序列号以及case状态
     *
     * @methodName: checkSerialNumber
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020/3/9 16:35
     **/
    @GetMapping("/checkSerialNumberAndCaseByServiceNotice")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "核对序列号接口", httpMethod = "GET", notes = "核对序列号接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务单主键ID", name = "serviceNo", required = true, defaultValue = "10009", dataType = "String", paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> checkSerialNumberAndCaseByServiceNotice(
            @RequestParam(value = "serviceNo", required = true) String serviceNo
    ) {
        try {
            JSONObject jsonObj = new JSONObject();
            StInfoUpdate stInfoUpdate = new StInfoUpdate();
            stInfoUpdate.setServiceNo(serviceNo);
            stInfoUpdate.setDelFlag("0");
            stInfoUpdate.setStatus(0L);
            List<StInfoUpdate> stInfoUpdateList = stInfoUpdateMapper.selectStInfoUpdateList(stInfoUpdate);
            if (ObjectUtils.isEmpty(stInfoUpdateList)) {
                jsonObj.put("caseIsClosed", "1");
            } else {
                jsonObj.put("caseIsClosed", "0");
            }
            ServiceNotice serviceNoticeTemp = new ServiceNotice();
            serviceNoticeTemp.setServiceNo(serviceNo);
            List<ServiceNotice> serviceNotices = serviceNoticeService.getTeamServiceNotice(serviceNoticeTemp);
            ServiceNotice serviceNoticeCheck = serviceNotices.get(0);
           if("安装准备".equals(serviceNoticeCheck.getSubServiceType())){
                jsonObj.put("ischecked", "1");
           }else {
               if ("2".equals(serviceNoticeCheck.getIsCheck())) {
                   jsonObj.put("ischecked", "1");
               } else {
                   jsonObj.put("ischecked", "0");
               }
           }
            return new ResponseWithData().success(jsonObj).code(200);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 仪器绑定二维码接口
     *
     * @param ServiceNoticeId
     * @param QrCode
     * @param EnginnerId
     * @methodName: bindingQrCode
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020/3/9 16:48
     **/
    @Log(title = "仪器绑定二维码接口", businessType = BusinessType.UPDATE)
    @GetMapping("/bindingQrCode")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "仪器绑定二维码接口", httpMethod = "GET", notes = "仪器绑定二维码接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务单主键", name = "ServiceNoticeId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "仪器二维码Code", name = "QrCode", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "员工ID", name = "EnginnerId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> bindingQrCode(
            @RequestParam(value = "ServiceNoticeId", required = true) String ServiceNoticeId,
            @RequestParam(value = "QrCode", required = true) String QrCode,
            @RequestParam(value = "EnginnerId", required = true) String EnginnerId
    ) {
        try {
            return serviceInstrumentService.bindingQrCode(ServiceNoticeId, QrCode, EnginnerId);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 信息修改申请接口
     *
     * @param updateApply
     * @methodName: updateApply
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020/3/21 15:42
     **/
    @Log(title = "信息修改申请接口", businessType = BusinessType.UPDATE)
    @PostMapping("/updateApply")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "信息修改申请接口", httpMethod = "POST", notes = "信息修改申请接口")
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> updateApply(@RequestBody UpdateApply updateApply) {
        try {
            return serviceInstrumentService.updateApply(updateApply);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 核对仪器序列号跳过接口
     *
     * @param updateApply
     * @methodName: skipApply
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: lianjun
     * @date: 2020/5/24 15:42
     **/
    @Log(title = "核对仪器序列号跳过接口", businessType = BusinessType.UPDATE)
    @PostMapping("/skipApply")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "核对仪器序列号跳过接口", httpMethod = "POST", notes = "核对仪器序列号跳过接口")
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> skipApply(@RequestBody UpdateApply updateApply) {
        try {
            return serviceInstrumentService.skipApply(updateApply);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }


    /**
     * 验证服务单是否绑定过AccoutFse
     *
     * @param ServiceNoticeId
     * @methodName: checkAccoutFse
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020/3/19 14:54
     **/
    @GetMapping("/checkAccoutFse")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "验证服务单是否绑定过AccoutFse", httpMethod = "GET", notes = "验证服务单是否绑定过AccoutFse")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务单主键ID", name = "ServiceNoticeId", required = true, defaultValue = "1", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功", response = ServiceNotice.class)
    })
    public ResponseWithData<?> checkAccoutFse(
            @RequestParam(value = "ServiceNoticeId", required = true) Long ServiceNoticeId
    ) {
        try {
            return serviceInstrumentService.checkAccoutFse(ServiceNoticeId);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 签到时验证服务单地址是否发生变更
     *
     * @param ServiceNoticeId
     * @param longitude
     * @param latitude
     * @methodName: checkAddressDistance
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020/3/23 8:44
     **/
    @GetMapping("/checkAddressDistance")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "签到时验证服务单地址是否发生变更", httpMethod = "GET", notes = "签到时验证服务单地址是否发生变更")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务单主键ID", name = "ServiceNoticeId", required = true, defaultValue = "1", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "经度", name = "longitude", required = true, defaultValue = "125.22", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "纬度", name = "latitude", required = true, defaultValue = "45.52", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> checkAddressDistance(
            @RequestParam(value = "ServiceNoticeId", required = true) String ServiceNoticeId,
            @RequestParam(value = "longitude", required = true) String longitude,
            @RequestParam(value = "latitude", required = true) String latitude
    ) {
        try {
            return serviceInstrumentService.checkAddressDistance(ServiceNoticeId, longitude, latitude);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 获取当前服务单的地理位置和经纬度
     *
     * @param ServiceNoticeId
     * @methodName: getInstrument
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020/3/23 11:25
     **/
    @GetMapping("/getInstrument")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "获取当前服务单的地理位置和经纬度", httpMethod = "GET", notes = "获取当前服务单的地理位置和经纬度")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务单主键ID", name = "ServiceNoticeId", required = true, defaultValue = "1", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> getInstrument(
            @RequestParam(value = "ServiceNoticeId", required = true) String ServiceNoticeId
    ) {
        try {
            return serviceInstrumentService.getInstrument(ServiceNoticeId);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 根据服务单主键ID更新仪器经纬度
     *
     * @param ServiceNoticeIds
     * @param longitude
     * @param latitude
     * @methodName: updateInstrument
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020/3/23 13:47
     **/
    @Log(title = "根据服务单主键ID更新仪器经纬度", businessType = BusinessType.UPDATE)
    @GetMapping("/updateInstrument")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "根据服务单主键ID更新仪器经纬度", httpMethod = "GET", notes = "根据服务单主键ID更新仪器经纬度")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务单主键ID(多个用，号分开)", name = "ServiceNoticeIds", required = true, defaultValue = "1", dataType = "Long", paramType = "query"),
            @ApiImplicitParam(value = "修改的经度", name = "longitude", required = true, defaultValue = "125.22", dataType = "Double", paramType = "query"),
            @ApiImplicitParam(value = "修改的纬度", name = "latitude", required = true, defaultValue = "43.01", dataType = "Double", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> updateInstrument(
            @RequestParam(value = "ServiceNoticeIds", required = true) String ServiceNoticeIds,
            @RequestParam(value = "longitude", required = true) Double longitude,
            @RequestParam(value = "latitude", required = true) Double latitude
    ) {
        try {
            return serviceInstrumentService.updateInstrument(ServiceNoticeIds, longitude, latitude);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }


    /**
     * 2.53查询仪器数据
     *
     * @param CustomerName
     * @param serialNo
     * @param Div
     * @param bu
     * @methodName: setPartAccountFSE
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: sjy
     * @date: 2020年3月23日18:39:53
     **/
    @GetMapping("/getInstrumentList")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "2.53查询仪器数据", httpMethod = "GET", notes = "2.53查询仪器数据")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "客户名称", name = "CustomerName", required = false, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "仪器序列号", name = "serialNo", required = false, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "Div", name = "Div", required = false, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "bu", name = "bu", required = false, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "starttime", name = "starttime", required = false, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "endtime", name = "endtime", required = false, defaultValue = "10009", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功", response = InstrumentInfo.class)
    })
    public ResponseWithData<?> getInstrumentList(
            @RequestParam(value = "CustomerName", required = false) String CustomerName,
            @RequestParam(value = "serialNo", required = false) String serialNo,
            @RequestParam(value = "Div", required = false) String Div,
            @RequestParam(value = "bu", required = false) String bu,
            @RequestParam(value = "starttime", required = false) String starttime,
            @RequestParam(value = "endtime", required = false) String endtime
    ) {
        try {
            return serviceInstrumentService.getInstrumentList(CustomerName, serialNo, Div, bu,starttime,endtime);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 2.54查询服务报告数据
     *
     * @methodName: syncAllServiceReport
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: wlf
     * @date: 2020-04-24 16:51
     **/
    @GetMapping("/syncAllServiceReport")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "2.54查询服务报告数据", httpMethod = "GET", notes = "2.54查询服务报告数据")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "仪器编号", name = "Instrument_id", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "开始日期", name = "starttime", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "结束日期", name = "endtime", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "客户名称", name = "CustName", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务大类key", name = "SnType", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "子类key", name = "SnSubType", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "序列号", name = "SerialNo", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "状态", name = "Status", required = false, dataType = "String", paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功", response = InstrumentInfo.class)
    })
    public ResponseWithData<?> syncAllServiceReport(
            @RequestParam(value = "Instrument_id", required = false) String Instrument_id,
            @RequestParam(value = "starttime", required = false) String starttime,
            @RequestParam(value = "endtime", required = false) String endtime,
            @RequestParam(value = "CustName", required = false) String CustName,
            @RequestParam(value = "SnType", required = false) String SnType,
            @RequestParam(value = "SnSubType", required = false) String SnSubType,
            @RequestParam(value = "SerialNo", required = false) String SerialNo,
            @RequestParam(value = "Status", required = false) String Status
    ) {
        try {
            return serviceInstrumentService.syncAllServiceReport(Instrument_id, starttime, endtime, CustName, SnType, SnSubType, SerialNo, Status);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 根据服务单号查询仪器(欢迎补充参数)
     *
     * @param params
     * @methodName: getInstrumentByServiceNo
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: wlf
     * @date: 2020/3/28 12:04
     **/
    @PostMapping("/getInstrumentByServiceNo")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "根据服务单号查询仪器", httpMethod = "POST", notes = "根据服务单号查询仪器")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务号", name = "serviceNo", dataType = "String", paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> getInstrumentByServiceNo(@RequestBody Map<String, Object> params) {
        try {
            List<JSONObject> list = serviceInstrumentService.getInstrumentByServiceNo(params);
            return new ResponseWithData().success(list).msg("success").code(200);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 工作台仪器二维码绑定
     *
     * @param instrumentInfo
     * @methodName: bingQrCode
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020-03-28 10:06
     **/
    @Log(title = "工作台仪器二维码绑定", businessType = BusinessType.UPDATE)
    @PostMapping("/bingQrCode")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "工作台仪器二维码绑定", httpMethod = "POST", notes = "工作台仪器二维码绑定")
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> bingQrCode(@RequestBody InstrumentInfo instrumentInfo) {
        try {
            return serviceInstrumentService.bingQrCode(instrumentInfo);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 2.51获取仪器配置清单接口
     *
     * @param instrumentCode
     * @param serviceNo
     * @param enginnerId
     * @methodName: getInstrumentFile
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020-05-09 8:55
     **/
    @GetMapping("/getInstrumentFile")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "2.51获取仪器配置清单接口", httpMethod = "GET", notes = "2.51获取仪器配置清单接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "仪器主键", name = "instrumentCode", required = true, defaultValue = "1", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务号", name = "serviceNo", required = true, defaultValue = "125.22", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "员工ID", name = "enginnerId", required = true, defaultValue = "43.01", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> getInstrumentFile(
            @RequestParam(value = "instrumentCode", required = true) String instrumentCode,
            @RequestParam(value = "serviceNo", required = true) String serviceNo,
            @RequestParam(value = "enginnerId", required = true) String enginnerId
    ) {
        try {
            JSONObject jsonObject = ccService.getInstrumentFile(instrumentCode, serviceNo, enginnerId);
            return new ResponseWithData<>().success(jsonObject).msg("查询成功").code(200);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }


}
